home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-02-12 | 6.2 KB | 240 lines | [TEXT/CWIE] |
- // CCMArea version 1.3.1
- // 11-11-97
- // by David Catmull
-
- /* History:
-
- 9-19-97 First version
-
- 10-6-97 Added optional references to UCursor
- Added sCursorID and SetCursorID
- Deletes trailing separators
- Added more comments
-
- 10-16-97 Modified GetSelectionDesc to call mSuperCMArea
- Made CMAdjustCursor static
-
- 10-18-97 Call ProcessCommand instead of ObeyCommand
-
- 10-21-97 Moved AddCommandToMenu, SetCMCursor, SetCursorID and intialization to UCMArea
- Removed CMAdjustCursor
-
- 11-11-97 Added delay click
-
- 11-19-97 Pass mouseDown to DelayClick
-
- 11-22-97 Multiple return values for CMClick
-
- 11-29-97 Added PostClick
-
- 12-20-97 Removed BalloonAvailable
-
- 2-12-98 Disposes of menus before handling selection
- */
-
- #include "CCMArea.h"
- #include "UCMArea.h"
- #include "CCMWindow.h"
- #include <LCommander.h>
- #include <LMenuBar.h>
- #include <LMenu.h>
-
- #include <Appearance.h>
-
- Int16 CCMArea::sMenuID = 999;
-
-
- /* ------------------------------------------------------------------------------------------------ */
-
- CCMArea::CCMArea(CCMArea *inSuperCMArea)
- {
- mSuperCMArea = inSuperCMArea;
- }
-
- /* ------------------------------------------------------------------------------------------------ */
- // CMClick
- // Build the menu, display it, and pass on the selected command
-
- short
- CCMArea::CMClick(const SMouseDownEvent &inMouseDown)
- {
- if (!UCMArea::HasContextualMenus())
- return cm_Nothing;
-
- if (!::IsShowContextualMenuClick(&inMouseDown.macEvent)) {
- if (DelayClick(inMouseDown)) {
- if (!UCMArea::WaitDelayClick(inMouseDown.macEvent))
- return cm_Nothing;
- }
- else
- return cm_Nothing;
- }
-
- MenuHandle menu = ::NewMenu(sMenuID,"\p");
- AEDesc selection = { typeNull,0L };
- Str255 helpString,itemText;
- UInt32 userSelection,*commandList;
- SInt16 menuID;
- UInt16 menuItem;
- OSStatus err;
- short i,itemCount;
- short returnValue = cm_Nothing;
- unsigned long selectedCommand = cmd_Nothing;
-
- PreClick(inMouseDown);
- BuildMenu(menu);
- GetSelectionDesc(selection);
-
- // Check for a trailing divider and remove it
- // Other wise we end up with two dividers if the plugins add anything
-
- ::GetMenuItemText(menu,::CountMenuItems(menu),itemText);
- if (itemText[1] == '-')
- ::DeleteMenuItem(menu,::CountMenuItems(menu));
-
- // Somehow ContextualMenuSelect strips out all the command IDs from the main menu,
- // so we have to make a backup list. Fortunately, submenus are unaffected.
-
- itemCount = ::CountMenuItems(menu);
-
- StPointerBlock commandBlock(sizeof(UInt32) * itemCount);
-
- commandList = (UInt32*) (Ptr)commandBlock;
- for (i = 1; i <= itemCount; i++)
- ::GetMenuItemCommandID(menu,i,&commandList[i-1]);
-
- ::InsertMenu(menu,hierMenu);
- GetHelpItemString(helpString);
- err = ::ContextualMenuSelect(menu,inMouseDown.macEvent.where,
- false,HelpType(),helpString,
- (selection.descriptorType == typeNull) ? 0L : &selection,
- &userSelection,&menuID,&menuItem);
-
- returnValue = cm_MenuDisplayed;
-
- CleanUpMenus();
- ::DeleteMenu(sMenuID);
- ::DisposeMenu(menu);
-
- switch (userSelection) {
-
- case kCMMenuItemSelected:
- if (menuID == sMenuID)
- selectedCommand = commandList[menuItem-1];
- else {
- MenuHandle subMenu;
-
- subMenu = ::GetMenuHandle(menuID);
- ::GetMenuItemCommandID(subMenu,menuItem,&selectedCommand);
- }
- LCommander::GetTarget()->ProcessCommand(selectedCommand);
- returnValue = cm_ItemChosen;
- break;
-
- case kCMShowHelpSelected:
- ShowHelp();
- returnValue = cm_ItemChosen;
- break;
-
- case kCMNothingSelected:
- case kCMShowBalloonSelected: // Balloons are handled automatically
- default:
- break;
- }
-
- PostClick(inMouseDown,returnValue,selectedCommand);
-
- return returnValue;
- }
-
- /* ------------------------------------------------------------------------------------------------ */
- // GetSelectionDesc
- // Return an Apple Event descriptor for the selection data
- // Override to make your data available to CM plugins
-
- void
- CCMArea::GetSelectionDesc(AEDesc &outSelDesc)
- {
- if (mSuperCMArea)
- mSuperCMArea->GetSelectionDesc(outSelDesc);
- }
-
- /* ------------------------------------------------------------------------------------------------ */
- // PreClick
- // Do any processing necessary before displaying the contextual menu
- // such as updating the command chain - LCommander::SwitchTarget(this)
-
- void
- CCMArea::PreClick(const SMouseDownEvent &inMouseDown)
- {
- #pragma unused (inMouseDown)
- }
-
- /* ------------------------------------------------------------------------------------------------ */
- // PostClick
- // Do any post-processing necessary after displaying the contextual menu
- // inCMResult is the same value to be returned by CMClick
- // but it will never be cm_Nothing
- // inCommand is the command that was selected, if any (cmd_Nothing otherwise)
-
- void
- CCMArea::PostClick(const SMouseDownEvent &inMouseDown,short inCMResult,CommandT inCommand)
- {
- #pragma unused (inMouseDown)
- #pragma unused (inCMResult)
- #pragma unused (inCommand)
- }
-
- /* ------------------------------------------------------------------------------------------------ */
- // BuildMenu
- // Construct the menu to be displayed
- // If the superCMArea added any items, append a separator
-
- void
- CCMArea::BuildMenu(MenuHandle inMenu)
- {
- short itemCount = ::CountMenuItems(inMenu);
-
- if (mSuperCMArea && AddSuperCommands())
- mSuperCMArea->BuildMenu(inMenu);
-
- // Add a separator if the superCMArea added any commands
- if (::CountMenuItems(inMenu) != itemCount)
- ::AppendMenu(inMenu,"\p-");
-
- BuildMenuSelf(inMenu);
- }
-
- /* ------------------------------------------------------------------------------------------------ */
- // BuildMenuSelf
- // Override to add your own commands
-
- void
- CCMArea::BuildMenuSelf(MenuHandle inMenu)
- {
- #pragma unused (inMenu)
- }
-
- /* ------------------------------------------------------------------------------------------------ */
- // DelayClick
- // Determine whether to use delay click
-
- Boolean
- CCMArea::DelayClick(const SMouseDownEvent &inMouseDown)
- {
- #pragma unused (inMouseDown)
-
- return UCMArea::GetDelayClick();
- }
-
- /* ------------------------------------------------------------------------------------------------ */
- // ShowHelp
- // Called when the user selects Help from the menu
- // You can open your Apple Guide file or whatever other help system you use
-
- void
- CCMArea::ShowHelp()
- {
- }
-
-